package com.wenhuitec.sysui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;


import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wenhuitec.sysui.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ApRadioBoxAdapter extends RecyclerView.Adapter<ApRadioBoxAdapter.MyHolder> {

    List<Map<String, String>> mapList = new ArrayList<>();
    private Context mContext;
    private int mSelectPos = 0;

    private OnUserClick onUserClick;

    public interface OnUserClick {
        void onClick(Map<String, String> map);
    }


    public ApRadioBoxAdapter(Context context, List<Map<String, String>> list, OnUserClick onUserClick) {
        this.mContext = context;
        this.mapList = list;
        this.onUserClick = onUserClick;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_radio2, parent, false);
        //将view传递给我们自定义的ViewHolder
        MyHolder holder = new MyHolder(view);
        //返回这个MyHolder实体
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        holder.name.setText(mapList.get(position).get("name"));
        holder.itemRadioMain.setOnClickListener((v -> {
            if (onUserClick != null) {
                onUserClick.onClick(mapList.get(position));
            }
        }));
    }

    @Override
    public int getItemCount() {
        return mapList.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        TextView name;
        LinearLayout itemRadioMain;

        public MyHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.nameTv);
            itemRadioMain = itemView.findViewById(R.id.item_radio_main);
        }
    }

}
